Skip to content

Add more efficient solution to Longest Consecutive Sequence - Python #2747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

ethancdaniel
Copy link
Collaborator

I noticed that in the video solution, values were being repeatedly iterated over. Making my small change of iterating over the items remaining in the set rather than the entire array improves speed from 1500 ms to 350 ms.

While they have the end up having the same Big O notation, I feel like it's a big enough speed improvement to include in the solutions. Since it differs from the video, I followed the contributing guidelines and added it as another method. I noticed the same problem in other languages and would be happy to update those in future PRs if this one goes through.

My solution
Screenshot 2023-08-01 at 5 01 53 PM

Current solution
Screenshot 2023-08-01 at 4 51 36 PM

@ethancdaniel ethancdaniel changed the title Add more efficient solution to #128 python Add more efficient solution to Longest Consecutive Sequence - Python Aug 2, 2023
@ethancdaniel
Copy link
Collaborator Author

Nvm, the entire speedup comes from iterating over the set rather than the array, so this is a duplicate of #2520.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant